//layui xtable
layui.define(['layer', 'table', 'form', 'laydate'], function (exports) {

    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        laydate = layui.laydate;

    //刷新
    form.on('submit(refresh)', function (data) {
        var values = data.field,
            elem = data.elem;
        $.get($(elem).attr('refreshurl'), function (result) {
            if (result.code == 0) {
                layer.msg(result.data, {
                    icon: 1
                });
                table.reload('table', {
                    where: values,
                    page:{
                        curr:1
                    }
                });
            } else {
                layer.msg(result.msg, {
                    icon: 2,
                    time: 5000
                });
            }
        });
        return false;
    });


    form.on('select(timeTypeSelect)', function(data){
        let timeType = data.value
        switch (timeType) {
            case '1':
                $("#monthDateType").show();
                $("#yearDateType").hide();
                break;
            case '2':
                $("#monthDateType").hide();
                $("#yearDateType").show();
                break;
            case '3':
                $("#monthDateType").hide();
                $("#yearDateType").hide();
                break;
            default:
                break;
        }
        return false
    });

    //月份
    $.each($('.layStatisticsMonth'), function (i, item) {
        laydate.render({
            elem: item,
            type: 'month',
            format: 'yyyyMM',
            max: 0
        });
    });

    //年份
    $.each($('.layStatisticsYear'), function (i, item) {
        laydate.render({
            elem: item,
            type: 'year',
            format: 'yyyy',
            max: 0
        });
    });


    exports('xstatistics', {});
});
